import requests
from bs4 import BeautifulSoup
import re
import os
dir='./jpg'
url = 'https://www.shejidaren.com/dribbble-beautiful-ui-design-last-half-of-2012.html'
# 1.确定地址，发送请求
response = requests.get(url)
# 2.转换数据类型

# 3.数据解析
html = response.text       # 可读网页源码
content =response.content  # 二进制网页源码
title = re.findall('<head>(.*?)</head>', html,flags=re.DOTALL)
results = list(set(re.findall('<img src="(.*?)" ', html)))
# 4.二次响应
if not os.path.exists(dir):
    os.mkdir(dir)
for i in range(len(results)):
    content = requests.get(results[i]).content
    with open(os.path.join(dir,'{}.jpg'.format(i)),'wb') as f:
        f.write(content)

print('Successfully!')
